package com.zj.androidcamera.util;

import android.graphics.Rect;
import android.util.Size;

public class MatrixUtil {

    public static Rect matrixTransformation(Size src, Rect srcRect, Size dst) {
        float widthRatio = dst.getWidth() / (float) src.getHeight();
        float heightRatio = dst.getHeight() / (float) src.getWidth();

        Rect dstRect = new Rect();
        dstRect.left = Math.round(widthRatio * srcRect.top);
        dstRect.top = Math.round(heightRatio * (src.getWidth() - srcRect.right));
        dstRect.right = Math.round(widthRatio * srcRect.bottom);
        dstRect.bottom = Math.round(heightRatio * (src.getWidth() - srcRect.left));

        return dstRect;
    }

}
